package agend.client.gui.panels;

import java.awt.Component;
import java.io.IOException;

import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import agend.client.gui.panels.agend.AgendPanel;
import agend.client.gui.panels.appointment.AppointmentPanel;
import agend.client.gui.panels.contacts.ManageContact;
import agend.client.gui.panels.more.MorePanel;
import agend.client.gui.panels.settings.SettingsPanel;
import agend.client.gui.utils.HandlerView;

import com.google.gdata.util.ServiceException;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Paolo
 */
public class MenuPanel extends javax.swing.JTabbedPane
{	
	private ManageContact contactsPanel;
	private AgendPanel agendPanel;
	private SettingsPanel settingsPanel;
	private MorePanel morePanel;
	private AppointmentPanel appointmentPanel;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// Variables declaration - do not modify//GEN-BEGIN:variables
	//    private javax.swing.JTabbedPane jTabbedPane;

	// End of variables declaration//GEN-END:variables

	/**
	 * Creates new form MenuPanel
	 * @throws ServiceException 
	 * @throws IOException 
	 */
	public MenuPanel()
	{
		initComponents();
		addListener();

	}
	
	private void addListener(){
		
		this.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent e) {
				// TODO Auto-generated method stub

				JTabbedPane tabSource = (JTabbedPane) e.getSource();
				String tab = tabSource.getTitleAt(tabSource.getSelectedIndex());
				if(tab.equals("Settings"))
					settingsPanel.loadDisponibilitaSettimanale();

			}
		});
		
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 * @throws ServiceException 
	 * @throws IOException 
	 */

	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents()
	{
		contactsPanel = new ManageContact();
		agendPanel = new AgendPanel();
		settingsPanel = new SettingsPanel();
		morePanel = new MorePanel();
		appointmentPanel = new AppointmentPanel();

		addTab("Contacts", contactsPanel);
		addTab("Agend", agendPanel);
		addTab("Appointment",appointmentPanel);
		addTab("Settings", settingsPanel);
		addTab("More", morePanel);

		this.addChangeListener(new ChangeListener() {
			// This method is called whenever the selected tab changes
			@Override
			public void stateChanged(ChangeEvent evt) {
				JTabbedPane pane = (JTabbedPane)evt.getSource();

				Component c = pane.getSelectedComponent();

				if(c instanceof AppointmentPanel)
				{
					HandlerView.getFrame().setSize(1000, 700);
				}
				if(c instanceof AgendPanel)
				{
					HandlerView.getFrame().setSize(1000, 700);
				}

			}
		});
	}




	public ManageContact getContactsPanel() {
		return contactsPanel;
	}

	public AgendPanel getAgendPanel() {
		return agendPanel;
	}

	public SettingsPanel getSettingsPanel() {
		return settingsPanel;
	}

	public MorePanel getMorePanel() {
		return morePanel;
	}
	public AppointmentPanel getAppointmentPanel() {
		return appointmentPanel;
	}

}
